package com.wnzt.baszh.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.wnzt.baszh.core.base.CommonServiceImpl;
import com.wnzt.baszh.dao.IUserDao;
import com.wnzt.baszh.entity.Tsysuser;
import com.wnzt.baszh.service.IUserService;
import com.wnzt.baszh.util.common.CryptoUtil;
import com.wnzt.baszh.util.common.ObjectMapper;

@Service
public class UserServiceImpl extends CommonServiceImpl implements IUserService {
    
    @Autowired
    private JdbcTemplate jdbcTemplate;
    
    @Autowired
    private IUserDao userDao;

    @Override
    public Tsysuser checkUser(String fusercode, String fpassword) {
        fpassword = CryptoUtil.aesEncrypt(fpassword);
        String sql = "SELECT * FROM TSYSUSER t WHERE t.FCODE='"+fusercode+"' AND t.FPASSWORD='"+fpassword+"'";
        @SuppressWarnings("unchecked")
        List<Tsysuser> users = jdbcTemplate.query(sql,new ObjectMapper(Tsysuser.class));
        if(users.size()>0){
            return users.get(0);
        }
        return null;
    }

	@Override
	public List<Map<String, Object>> getmenulistByUser(String fgroupcode) {
		List<Map<String, Object>> list = userDao.getMenu(fgroupcode);
		return list;
	}

	@Override
	public Tsysuser checkUserCA(String casn, String password) {
		password = CryptoUtil.aesEncrypt(password);
        String sql = "SELECT * FROM TSYSUSER t WHERE t.FNETCASN='"+casn+"' AND t.FPASSWORD='"+password+"'";
        @SuppressWarnings("unchecked")
        List<Tsysuser> users = jdbcTemplate.query(sql,new ObjectMapper(Tsysuser.class));
        if(users.size()>0){
            return users.get(0);
        }
        return null;
	}

}
